<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}</title>
<%@ include file="css_js_base.jsp"%>
<link href="static/css/jquery-ui-1.10.3.full.min.css" rel="stylesheet">
<script type="text/javascript" src="static/js/lib/jquery-ui-1.10.3.full.min.js"></script>
<script type="text/javascript">
$(function(){
	$('#inputForm').checkForm();
	//$(".dd-list" ).sortable();
	$("#sortable" ).sortable();
	$(".radioBtn").button();
	
    $('#inputForm').ajaxForm({ 
        type: "post",
        dataType:"json",
        beforeSubmit: function(){
	       $("#sbmBtn").attr("disabled",null);
	       return true;
        },
        clearForm: false,
        resetForm: false,
        success: function(resp){
        	if(resp.status == '1' ){
        		ui.msg(resp.msg, 1);
        	}else{
        		ui.msg(resp.msg, 0);
        	}
        	$("#sbmBtn").removeClass("disabled").attr("disabled",null);
        },
        error:function(resp){
        	ui.msg('请求发送失败', 0);
    		$("#sbmBtn").removeClass("disabled").attr("disabled",null);
        }
    }); 
});

function sbmForm(){
	//var sortedIDs = $( ".dd-list" ).sortable( "toArray" );
	var sortedIDs = $( "#sortable" ).sortable( "toArray" );
    $('#ords').val(sortedIDs);
    $('#inputForm').submit();
}


function showOpt(name,obj){
	var obj = $(obj);
	var val = obj.val();
	if('select' == val){
		$('#'+name+'_optBtn').removeClass('hide');	
		
		addOption(name);
		addOption(name);
	}else{
		$('#'+name+'_optBtn').addClass('hide');	
		$('#'+name+'_select').html('');
	}
}

function addOption(name){
	var tpl = '<div class="form-group" id="'+name+'_select_group">'
	+'<label class="col-sm-3 control-label no-padding-right">key-vale</label>'
	+'<div class="col-sm-9">'
	+'	<input type="text" class="col-sm-3" value=""  name="'+name+'_select_option_val" />'
	+'	<input type="text" class="col-sm-4" value=""  name="'+name+'_select_option_name" />'
	+'	&nbsp;'
	+'	<a href="javascript:void(0)" onclick=\'removeOption("'+name+'")\' class="btn btn-xs btn-warning">删除</a>'
	+'</div>'
	+'</div>';
	
	$('#'+name+'_select').append(tpl);
}

function removeOption(name){
	$('#'+name+'_select_group').remove();
} 
</script>
<style type="text/css">
.dd-list{
	list-style:none;
}
.dd-item{
	/*margin:12px 0;
	padding:12px;
	background:#e7e7e7;
	border:1px solid #dedede;*/
}
#sortable { list-style-type: none; }
#sortable li {margin: 3px 3px 3px 0; padding: 5px; text-align: center; }
</style>
</head>
<body>
<%@ include file="navbar.jsp"%>
<div class="container">
	<div class="col-md-12">
		<form class="form-horizontal" role="form" id="inputForm" action="${ctx}/codematic/codematic_server.jsp?action=gen_code" method="post">
			<input type="hidden" name="entity" value="${entity}"/>
			<input type="hidden" name="ords" id="ords" value=""/>

			<div class="form-group">
				<label class="col-sm-3 control-label">entity *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${entity}" disabled="disabled"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">entityPkg *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="entityPkg" id="entityPkg"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">daoPkg *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="daoPkg" id="daoPkg"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label">servicePkg *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="servicePkg" id="servicePkg"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label">controllerPkg *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="controllerPkg" id="controllerPkg"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label">moduleUri *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="moduleUri" id="moduleUri"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>

			<div class="form-group">
				<label class="col-sm-3 control-label">viewPkg *</label>
				<div class="col-sm-9">
				<input type="text" class="form-control" 
				value="${moduleUri}"  name="viewPkg" id="viewPkg"  datatype="require"
				msg="必填项" title="必填项"/>
				</div>
			</div>

			<div class="space-4"></div>


			<div class="hr hr-solid"></div>
			<div class="form-group">
				<div class="col-xs-12 text-center">
					<h4>字段属性，可以拖拽进行排序</h4>
					<ul id="sortable" class="list-unstyled">
						<c:forEach var="vo" items="${data_list}" varStatus="st">
						<c:if test="${'id' != vo.name && 'created' != vo.name && 'modified' != vo.name && 'cuid' != vo.name && 'muid' != vo.name }">
						<li class="inline pull-left" id="${vo.name}" style="margin:0 12px;"><span class="label label-info">${vo.name}</span></li>
						</c:if>
						</c:forEach>
					</ul>
				</div>
			</div>
			<div class="hr hr-solid"></div>

			<div class="dd" style="margin:0 auto;">
				<ol class="dd-list">
					<c:forEach var="vo" items="${data_list}" varStatus="st">
					<c:if test="${'id' != vo.name && 'created' != vo.name && 'modified' != vo.name && 'cuid' != vo.name && 'muid' != vo.name }">
					<li class="dd-item well">
						<div class="dd-handle">
							<h3>${vo.name}</h3>
							<div class="form-group">
								<label class="col-sm-3 control-label">字段名称</label>
								<div class="col-sm-9">
								<input type="text" class="form-control" value="<c:if test="${ 'note' == vo.name}">备注</c:if>"  name="${vo.name}_cn"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否显示</label>
								<div class="col-sm-9">
								<%-- <select name="${vo.name}_show" class="form-control">
								<option value="0">否</option>
								<option value="1">是</option>
								</select> --%>
									<div class="btn-group">
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_show" id="${vo.name}_show1" checked> 是
									  </label>
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_show" id="${vo.name}_show2"> 否
									  </label>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否搜索</label>
								<div class="col-sm-9">
								<%-- <select name="${vo.name}_search" class="form-control">
								<option value="0">否</option>
								<option value="1">是</option>
								</select> --%>
									<div class="btn-group">
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_search" id="${vo.name}_search1"> 是
									  </label>
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_search" id="${vo.name}_search2" checked> 否
									  </label>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否表单项</label>
								<div class="col-sm-9">
								<%-- <select name="${vo.name}_formField" class="form-control">
								<option value="1">是</option>
								<option value="0">否</option>
								</select> --%>
									<div class="btn-group">
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_formField" id="${vo.name}_formField1" checked> 是
									  </label>
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_formField" id="${vo.name}_formField2"> 否
									  </label>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">文本框类型</label>
								<div class="col-sm-9">
								<select name="${vo.name}_formType" class="form-control" onChange="showOpt('${vo.name}',this)">
								<option value="input">input</option>
								<option value="textarea" <c:if test="${ 'note' == vo.name}">selected</c:if>>textarea</option>
								<option value="select">select</option>
								</select>
								&nbsp;
								<a href="javascript:void(0)" onclick="addOption('${vo.name}');" class="btn btn-xs btn-success hide" id="${vo.name}_optBtn">新增option项</a>
								</div>
							</div>
							<div id="${vo.name}_select">
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否必填项</label>
								<div class="col-sm-9">
								<%-- <select name="${vo.name}_validate" class="form-control">
								<option value="0">否</option>
								<option value="1">是</option>
								</select> --%>
									<div class="btn-group">
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_validate" id="${vo.name}_validate1"> 是
									  </label>
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_validate" id="${vo.name}_validate2" checked> 否
									  </label>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否AJAX校验</label>
								<div class="col-sm-9">
								<%-- <select name="${vo.name}_ajaxCheck" class="form-control">
								<option value="0">否</option>
								<option value="1">是</option>
								</select> --%>
									<div class="btn-group">
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_ajaxCheck" id="${vo.name}_ajaxCheck1"> 是
									  </label>
									  <label class="radioBtn btn btn-primary">
									    <input type="radio" name="${vo.name}_ajaxCheck" id="${vo.name}_ajaxCheck2" checked> 否
									  </label>
									</div>
								</div>
							</div>
						</div>
					</li>
					</c:if>
					</c:forEach>
				</ol>
			</div>

			<div class="clearfix form-group">
			<div class="col-md-offset-3 col-md-9">
			<button type="button" class="btn btn-success" id="sbmBtn" onclick="sbmForm()"><i class="icon-ok bigger-110"></i>生成代码</button>
			</div>
			</div>
		</form>
	</div>
</div>
</body>
</html>
